package com.cn.stepLock.chain;

import com.cn.stepLock.enums.ExecuteStatus;
import com.cn.stepLock.executeLambda.BaseConsumer;
import com.cn.stepLock.executeLambda.BaseLambda;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Aaron
 * @desc
 * @createTime 2022-02-21 21:14
 * @since
 */
public class Task {

    BaseConsumer baseExecuteLambda;

    Thread ownerThread;

    int status;

    /**
     * 实际执行的时候下一步绑定的任务
     */
    Task nextStepInvokeTask;
    /**
     * 实际执行的时候上一步绑定的任务
     */
    List<Task> preStepInvoeTaskList;
    /**
     * 同一线程内调用链的下一个任务
     */
    Task nextChainTask;
    /**
     * 同一线程内调用链的上一个任务
     */
    Task preChainTask;
    /**
     * 在每个chain中双向队列的下一个值
     */
    Task nextQueueTask;
    /**
     * 在每个chain中双向队列的上一个值
     */
    Task preQueueTask;

    Throwable throwable;

    boolean finaleFinished;

    ProcessChain chain;

    boolean  unparkPresentTask;

    private int index;

    public Task(BaseConsumer consumer, Thread ownerThread) {
        this.baseExecuteLambda = consumer;
        this.ownerThread = ownerThread;
        this.status = ExecuteStatus.NOT_START.getValue();
        this.preStepInvoeTaskList=new ArrayList<>();
        this.finaleFinished = false;
    }

    public Task() {

    }

    void executeTask(){
        baseExecuteLambda.execute();
    }


    public void addQueueTask(Task task){
        this.nextQueueTask = task;
        task.preQueueTask=this;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }
}
